(*
  Copyright (c) 2009 Barry Schwartz

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
*)

open IO_Base
open XNum
open UniTools
  
type istream = IO_Base.istream
type irstream = IO_Base.irstream
type ostream = IO_Base.ostream
type orstream = IO_Base.orstream
type iostream = IO_Base.iostream
type iorstream = IO_Base.iorstream

val coerce_i : [> | io_r] io -> istream
val coerce_o : [> | io_w] io -> ostream
val coerce_ir : [> | io_rs] io -> irstream
val coerce_or : [> | io_ws] io -> orstream
val coerce_io : [> | io_rw] io -> iostream
val coerce_ior : [> | io_rws] io -> iorstream
  
(* IO routines *)
val size : [> | io_s] io -> int
val pos : [> | io_s] io -> int
val seek : [> | io_s] io -> int -> unit
val skip : [> | io_r] io -> int -> unit
val bytes_written : [> | io_w] io -> int
val eof : [> | io_r] io -> bool
val free : 'a io -> unit
  
(* Append the contents of a channel to a stream. *)
val append_channel : [> | io_w] io -> in_channel -> unit
val append : [> | io_w] io -> [> | io_r] io -> unit
  
(* Write the contents of a stream to a channel. *)
val to_channel : [> | io_r] io -> out_channel -> unit
val to_string : [> | io_rs] io -> string
val from_string : string -> iorstream
val to_buffer : [> | io_r] io -> iorstream
val sub_stream : [> | io_r] io -> int -> iorstream
  
(* reading from a stream *)
val read_char : [> | io_r] io -> char
val read_byte : [> | io_r] io -> int
val read_string : [> | io_r] io -> int -> string
val peek_char : [> | io_rs] io -> int -> char
val peek_string : [> | io_rs] io -> int -> int -> string
val skip_while : [> | io_rs] io -> (char -> bool) -> unit
  
(* reading bigendian integers *)
val read_be_u8 : [> | io_r] io -> int
val read_be_u16 : [> | io_r] io -> int
val read_be_u24 : [> | io_r] io -> int
val read_be_u32 : [> | io_r] io -> num
val read_be_i8 : [> | io_r] io -> int
val read_be_i16 : [> | io_r] io -> int
val read_be_i24 : [> | io_r] io -> int
val read_be_i32 : [> | io_r] io -> num
val read_utf8_char : [> | io_r] io -> int
  
(* writing to a stream *)
val write_char : [> | io_w] io -> char -> unit
val write_byte : [> | io_w] io -> int -> unit
val write_string : [> | io_w] io -> string -> unit
val printf : [> | io_w] io -> ('a, unit, string, unit) format4 -> 'a
val write_be_u8 : [> | io_w] io -> int -> unit
val write_be_u16 : [> | io_w] io -> int -> unit
val write_be_u24 : [> | io_w] io -> int -> unit
val write_be_u32 : [> | io_w] io -> num -> unit
val write_be_i8 : [> | io_w] io -> int -> unit
val write_be_i16 : [> | io_w] io -> int -> unit
val write_be_i24 : [> | io_w] io -> int -> unit
val write_be_i32 : [> | io_w] io -> num -> unit
val write_utf8_char : [> | io_w] io -> int -> unit
  
(* implementations *)
val make_in_stream : UniText.t -> istream
val make_out_stream : UniText.t -> ostream
val make_rand_in_stream : UniText.t -> irstream
val make_buffer_stream : int -> iorstream
val make_string_stream : string -> irstream
  

